package com.jshoperxms.mongo.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.jshoperxms.mongo.dao.RepositoryDao;
import com.jshoperxms.mongo.service.RepositoryService;
import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import com.mongodb.DBObject;

@Service("repositoryService")
@Scope("prototype")
public class RepositoryServiceImpl<T> implements RepositoryService<T> {
	@Resource
	private RepositoryDao<T> repositoryDao;

	@Override
	public void insert(T t) {
		repositoryDao.insert(t);
	}

	@Override
	public void insertAll(List<T> t) {
		repositoryDao.insertAll(t);
	}

	@Override
	public boolean deleteById(String id, Class<T> t) {
		return repositoryDao.deleteById(id, t);
	}

	@Override
	public void delete(T t) {
		repositoryDao.delete(t);

	}

	@Override
	public T findOne(Query query, Class<T> t) {
		return repositoryDao.findOne(query, t);
	}

	@Override
	public boolean updateFirst(Query query, Update update, Class<T> t) {
		return repositoryDao.updateFirst(query, update, t);
	}

	@Override
	public List<T> findAll(Class<T> t) {
		return repositoryDao.findAll(t);
	}

	@Override
	public Long getCount(Query query, Class<T> t) {
		return repositoryDao.getCount(query, t);
	}

	@Override
	public List<T> findAll(Query query, Class<T> t) {
		return repositoryDao.findAll(query, t);
	}

	@Override
	public List<T> findByPage(Query query, int currentPage, int lineSize,
			Class<T> t) {
		return repositoryDao.findByPage(query, currentPage, lineSize, t);
	}

	@Override
	public T findAndModify(Query query, Update update, Class<T> t) {
		return repositoryDao.findAndModify(query, update, t);
	}

	@Override
	public T findAndRemove(Query query, Class<T> t) {
		return repositoryDao.findAndRemove(query, t);
	}

	@Override
	public void saveOrUpdate(T t) {
		repositoryDao.saveOrUpdate(t);
	}

	@Override
	public boolean updateMulti(Query query, Update update, Class<T> t) {
		return repositoryDao.updateMulti(query, update, t);
	}

	@Override
	public boolean upsert(Query query, Update update, Class<T> t) {
		return repositoryDao.upsert(query, update, t);
	}

	@Override
	public void drop(Class<T> t) {
		repositoryDao.drop(t);

	}

	@Override
	public List<DBObject> geoNear(String collection, DBObject query,
			double[] point, int limit, long maxDistance) {
		return repositoryDao.geoNear(collection, query, point, limit,
				maxDistance);
	}

	@Override
	public List<DBObject> withinCircle(String collection, String locationField,
			double[] center, long radius, DBObject fields, DBObject query,
			int limit) {
		return repositoryDao.withinCircle(collection, locationField, center,
				radius, fields, query, limit);
	}

	@Override
	public List<DBObject> nearSphere(String collection, String locationField,
			double[] center, long minDistance, long maxDistance,
			DBObject query, DBObject fields, int limit) {
		return repositoryDao.nearSphere(collection, locationField, center,
				minDistance, maxDistance, query, fields, limit);
	}

	@Override
	public List<DBObject> withinPolygon(String collection,
			String locationField, List<double[]> polygon, DBObject fields,
			DBObject query, int limit) {
		return repositoryDao.withinPolygon(collection, locationField, polygon,
				fields, query, limit);

	}

	@Override
	public List<DBObject> withinMultiPolygon(String collection,
			String locationField, List<List<double[]>> polygons,
			DBObject fields, DBObject query, int limit) {
		return repositoryDao.withinMultiPolygon(collection, locationField,
				polygons, fields, query, limit);
	}

	@Override
	public List<DBObject> withinBox(String collection, String locationField,
			double[] bottomLeft, double[] upperRight, DBObject fields,
			DBObject query, int limit) {
		return repositoryDao.withinBox(collection, locationField, bottomLeft,
				upperRight, fields, query, limit);
	}

}
